/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.caelum.interceptor;

import br.com.caelum.controller.ProdutoController;
import br.com.caelum.model.UsuarioWeb;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.resource.ResourceMethod;

/**
 *
 * @author Rachid
 */
@Intercepts
public class VerificacaoInterceptor implements Interceptor{
    private UsuarioWeb usuarioWeb;
    private Result result;

    public VerificacaoInterceptor(UsuarioWeb usuarioWeb, Result result) {
        this.usuarioWeb = usuarioWeb;
        this.result = result;
    }

    public void intercept(InterceptorStack is, ResourceMethod rm, Object o) throws InterceptionException {
        System.out.println("oi");
        //result.redirectTo(ProdutoController.class).lista();
        is.next(rm, o);
    }

    public boolean accepts(ResourceMethod rm) {
        Boolean x = usuarioWeb.isLogado();
        Boolean y = !this.usuarioWeb.isLogado();
        System.out.println(x+" - "+y);
       return !this.usuarioWeb.isLogado();
    }

}
